﻿using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;

namespace UI
{
    public partial class edit : Form
    {
        public edit()
        {
            InitializeComponent();
        }

        private void edit_Load(object sender, EventArgs e)
        {
            txtQH.Text = String.Format("{0:yyyyMMdd}{1:D3}", DateTime.Now, 1);
        }

        private void button9_CheckedChange(UI.Control.Button sender, EventArgs e)
        {
            if (!sender.Checked)
            {
                showNumber1.RemoveNumber(sender.Value);
            }
            else
            {
                if (!showNumber1.AddNumber(sender.Value))
                {
                    sender.Checked = false;
                }
            }
        }

        private void showNumber1_NumberChanged()
        {
            foreach (System.Windows.Forms.Control c in p_btns.Controls)
            {
                Control.Button b = c as Control.Button;
                b.Enabled = true;
            }
            if (showNumber1.NumberCount == showNumber1.CanSelectedCount)
            {
                btn_OK.Enabled = true;
                foreach (System.Windows.Forms.Control c in p_btns.Controls)
                {
                    Control.Button b = c as Control.Button;
                    b.Enabled = b.Checked;
                }
            }
            else
            {
                btn_OK.Enabled = false;
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            string qh = txtQH.Text.Trim();
            if (qh.Length != 11)
            {
                MessageBox.Show("期号错误!", "提示");
                return;
            }

            
            btn_OK.Enabled = false;
            btn_clear.Enabled = false;
            btn_exit.Enabled = false;

            string result = this.showNumber1.Value.Trim();
            string phase = txtQH.Text.Trim();

            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("phase", phase);
            dict.Add("result", result);
            new Input.Core.WebUtils().DoPost("http://tv.kkcai.net/add.aspx", dict);
       

            

            btn_clear.Enabled = true;
            btn_exit.Enabled = true;
            MessageBox.Show("添加完成!", "提示");
        }

        private void btn_clear_Click(object sender, EventArgs e)
        {
            showNumber1.ClearNumber();
            foreach (System.Windows.Forms.Control c in p_btns.Controls)
            {
                Control.Button b = c as Control.Button;
                b.Enabled = true;
                b.Checked = false;
            }
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
